from rest_framework import serializers

from areas.models import Areas


class AreasSerializer(serializers.ModelSerializer):
    """省级行政区划展示序列化器"""

    class Meta:
        model = Areas
        fields = ['id', 'name']


class SubAreasSerializer(serializers.ModelSerializer):
    """子级行政区划显示序列化器"""
    # 显示子级行政区划需要连同父级的信息一起显示  不能只显示id或者名字
    subs = AreasSerializer(many=True, read_only=True)

    class Meta:
        model = Areas
        fields = ['id', 'name', 'subs']
